package io.zerous.tile;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Array;

/**
 * Created by Zerous on 2017/12/14.
 */

public class World {
    public Array<Entity> entities = new Array<Entity>();


    public World() {

    }

    public void addEntity(Entity entity) {
        entities.add(entity);
    }

    public void update() {
        for (Entity e: entities) {
            e.velocity.add(e.accel);
            tryMove(e);
        }
    }

    public void tryMove(Entity e) {
        e.position.x += e.velocity.x;
        if (e.position.x + 8 > Gdx.graphics.getWidth()) {
            e.position.x = Gdx.graphics.getWidth() - 8.01f;
            e.velocity.x = 0;
        } else if(e.position.x < 0) {
            e.position.x = 0.01f;
            e.velocity.x = 0;
        }
        e.position.y += e.velocity.y;
        if (e.position.y + 8 > Gdx.graphics.getHeight()) {
            e.position.y = Gdx.graphics.getHeight() - 8.01f;
            e.velocity.y = 0;
        } else if(e.position.y < 0) {
            e.position.y = 0.01f;
            e.velocity.y = 0;
        }
    }

}
